import api from "../../api/login.js";
import {
  setLoginInfo
} from '../../utils/loginInfo.js'
Component({
  methods: {
    async getPhoneNumber(e) {
      wx.login({
        success: res => {
          api.minappLogin({
            code: res.code,
            phoneCode: e.detail.code,
            encryptedData: e.detail.code,
            iv: e.detail.iv
          }).then(async resLog => {
            if (resLog.code === 0) {
              await setLoginInfo(resLog.data) // 设置登录信息
              wx.switchTab({
                url: '/pages/index/index',
              })
            }
          })
        }
      })
    },
    onGoLogin() {
      wx.reLaunch({
        url: '/pages/login/index',
      })
    }
  }
})